<?php

class Sides
{
    private $_sides = array();

    public static function fromRange($min, $max, $side_builder)
    {
        $sides = array();

        for ($min; $min <= $max; $min++) {
            $sides[] = $side_builder->build($min);
        }

        $sides_object = new Sides($sides);

        return $sides_object;
    }

    public function __construct($sides)
    {
        $this->setSides($sides);
    }

    public function setSides($sides)
    {
        $this->_sides = $sides;
    }

    public function getSides()
    {
        return $this->_sides;
    }

    public function getNumSides()
    {
        return count($this->getSides());
    }

    public function getSideAtIndex($index)
    {
        if ($index > $this->getNumSides()) {
            throw new Exception("There is no side at $index");
        }

        $sides = $this->getSides();

        $side = $sides[$index];

        return $side;
    }
}
